/*
 * @LastEditTime: 2023-02-28 14:38:06
 */
import { router } from "../index";
import { Lyrics } from "../../Models/Lyrics.schema";
import { LyricsController } from "../../Controller/Lyrics.controller"
import { createLyricsDTO,updateLyricsDTO } from "../../DTO/Lyrics.dto";

const LyricsModel = new LyricsController(Lyrics);

// router.prefix("/api/lyrics");

//按id获取歌词
router.get("/lyrics/:id", async (ctx, next) => {
  if (ctx.params.id){
    ctx.body = await LyricsModel.findById(ctx.params.id);  
  }
})
// 创建歌词
router.post('/lyrics', async (ctx, next) => {
  ctx.body = await LyricsModel.createItem(ctx.request.body as createLyricsDTO);
});
//删除歌词
router.delete("/lyrics/:id", async (ctx, next) => {
  ctx.body = await LyricsModel.removeById(ctx.params.id);
});

// 更新歌词
router.patch("/lyrics/:id", async (ctx, next) => {
  if(ctx.params.id)
  ctx.body = await LyricsModel.updateById(
    ctx.params.id,
    ctx.request.body as updateLyricsDTO
  );
});